package com.cdut.cn.boke.pojo;

import lombok.Data;

/**
 * 统一返回值
 */
@Data
public class ResponseData {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String message;


    /**
     * 数据
     */
    private Object data;

    /**
     *全参构造用于下面方法构造返回数据
     */
    public ResponseData(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 传参data请求成功
     * */
    public static ResponseData sucecss(Object data){
        ResponseData resp = new ResponseData(200,"success",data);
        return resp;
    }

    /**
     * 传参message，data请求成功
     */
    public static ResponseData sucecss(String msg,Object data){
        ResponseData resp = new ResponseData(200,msg,data);
        return resp;
    }

    /**
     * 传参自定义枚举类请求错误
     * */
    public static ResponseData error(ExceptionCodeMsgEnum exceptionCodeMsgEnum){
        ResponseData resp = new ResponseData(exceptionCodeMsgEnum.getCode(), exceptionCodeMsgEnum.getMessage(), null);
        return resp;
    }

    /**
     *传参状态码+message请求错误
     */
    public static ResponseData error(int code,String msg){
        ResponseData resp = new ResponseData(code,msg, null);
        return resp;
    }
}
